import axios from 'axios'
import tipMessage from "@/utils/tipMessage"

/**
 * 提示函数
 */
const tip = (msg) => {
    tipMessage(msg, 'error');
};

/**
 * axios基础设置
 * @type {number}
 */
axios.defaults.timeout = 15000;

//创建axios实例
const localInstance = axios.create({});

/**
 * axios基础设置
 * @type {number}
 */
localInstance.interceptors.response.use(
    (response) => {
        if (response.status === 200){
            return Promise.resolve(response.data);
        }else{
            tip(error.message);
            return Promise.reject(error);
        }
    },
    (error) => {
        tip(error.message);
        return Promise.reject(error);
    }
)

let baseLocalUrl = import.meta.env.MODE === "development" ? '../' : '';
const localApi = {
    /**
     * 请求本地文件
     */
    getLocal(url) {
        return localInstance.get(baseLocalUrl + url);
    }
}
export default localApi
